<template>
  <div class="taskContainer">
    <a-tabs
      v-if="route.query.template == 1"
      v-model:activeKey="groupValue"
      tab-position="top"
      @change="groupChange"
    >
      <a-tab-pane key="" :tab="t('control', '全部')"></a-tab-pane>
      <a-tab-pane
        v-for="(item, i) in allStudentStructure"
        :key="item.teamId"
        :tab="item.name"
      ></a-tab-pane>
    </a-tabs>

    <div class="header">
      <div style="display: flex; align-items: center; flex-wrap: wrap">
        <a-input
          v-model:value="searchData.search_AND_LIKE_title"
          :placeholder="t('control', '请输入任务标题')"
          style="width: 200px; margin-right: 12px"
        />
        <a-select
          ref="select"
          v-model:value="searchData.search_AND_EQ_weekId"
          style="width: 260px; margin-right: 10px"
          :placeholder="t('control', '教学周')"
          show-search
          :field-names="{ label: 'name', value: 'id' }"
          :options="teachingWeekOptions"
          :filter-option="filterWeekOption"
        >
        </a-select>
        <a-select
          ref="select"
          style="width: 200px; margin-right: 10px"
          v-model:value="searchData.search_AND_EQ_status"
          :placeholder="t('control', '请选择状态')"
          @focus="focus"
          @change="handleChange"
        >
        <!--  search_AND_EQ_status：0:未发布、1：已发布、2：已完成、3：已评分 -->
          <a-select-option :value="0">{{t('control', '未发布')}}</a-select-option>
          <a-select-option :value="1">{{t('control', '已发布')}}</a-select-option>
          <a-select-option :value="2">{{t('control', '已完成')}}</a-select-option>
          <a-select-option :value="3">{{t('control', '已评分')}}</a-select-option>

        </a-select>
        <!-- <a-select ref="select" v-model:value="searchData.search_AND_EQ_status"
					style="width: 120px; margin-right: 10px" placeholder="状态" :options="publishStatusOptions">
				</a-select>

				<a-select ref="select" v-model:value="searchData.search_AND_EQ_weekId"
					style="width: 260px; margin-right: 10px" placeholder="教学周" show-search
					:field-names="{ label: 'name', value: 'id' }" :options="teachingWeekOptions"
					:filter-option="filterWeekOption">
				</a-select>
				<div style='margin-right:15px'>
					发布时间：
					<minRangePicker style="width:260px" picker="datetime"
						v-model:startTime="searchData.publishStartTime" v-model:endTime="searchData.publishEndTime"
						placeholder='发布时间' />
				</div>
				<div>
					截止时间：
					<minRangePicker style="width:260px" picker="datetime"
						v-model:startTime="searchData.publishStartTime" v-model:endTime="searchData.publishEndTime"
						placeholder='发布时间' />
				</div> -->
      </div>
      <div>
        <a-button type="primary" @click="() => search(page, pageSize)"
          >{{t('control', '查询')}}</a-button
        >
        <a-button style="margin-left: 10px" @click="clear">{{t('control', '重置')}}</a-button>
      </div>
    </div>

    <div class="header" style="margin-top: 20px">
      <div>
        <!-- <a-radio-group v-model:value="groupValue">
								<a-radio-button value="">全部</a-radio-button>
				        <a-radio-button v-for='item in allStudentStructure' :value="item.teamId">{{item.teamName}}组</a-radio-button>
				        
				  </a-radio-group> -->
      </div>
      <div>
        <a-button type="primary" @click="handleClick({ name: 'AI生成任务' })"
          >{{ t('common', 'AI生成任务') }}</a-button
        >
        <a-button
          style="margin-left: 10px"
          @click="handleClick({ name: '创建任务' })"
          >{{ t('common', '创建任务') }}</a-button
        >
        <a-button
          style="margin-left: 10px"
          :disabled="!selectedRowKeys.length"
          @click="handleClick({ name: '批量发布' })"
          >{{ t('common', '批量发布') }}</a-button
        >
        <a-button
					:loading="delLoading"
          style="margin-left: 10px"
          :disabled="!selectedRowKeys.length"
          @click="handleClick({ name: '批量删除' })"
          >{{ t('common', '批量删除') }}</a-button
        >
      </div>
    </div>

    <div class="content">
      <div style="flex: 1; min-height: 0; overflow-y: auto;overflow-x: hidden; height: 100%">
        <a-table
          :dataSource="tableData"
          :columns="columns"
          :pagination="false"
          rowKey="id"
          :row-selection="{
            checkStrictly: false,
            selectedRowKeys: selectedRowKeys,
            onChange: onSelectChange,
          }"
        >
          <!-- <template #bodyRow="{ record }">
							<tr :style="{ color: dayjs(record.expiredTime).isBefore(dayjs()) ? 'red' : 'black' }">
								<td v-for="column in columns" :key="column.dataIndex">
									{{ record[column.dataIndex] }}
								</td>
							</tr>
					</template> -->

          <template #bodyCell="{ column, text, record, index }">
            <template v-if="column.key === 'title'">
              <a-tooltip placement="topLeft">
                <template #title>
                  <span>{{ text }}</span>
                </template>
                <span
                  style="
                    display: inline-block;
                    max-width: 100%;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                  "
                >
                  {{ text }}
                </span>
              </a-tooltip>
            </template>

            <template v-if="column.key === 'operate'">
              <div
                style="gap: 10px; width: 100px; display: flex; flex-wrap: wrap"
              >
                <a-popconfirm
                  :title="t('table', '确定删除吗？')"
                  @confirm="handleClick({ name: '删除', record, index })"
                >
                  <a style="color: #ff454a">{{t('common', '删除')}}</a>
                </a-popconfirm>
                <a @click="handleClick({ name: '查看', record, index })"
                  >{{t('common', '查看')}}</a
                >
                <a-popconfirm
                  :title="`${record.status == 0 ? t('table', '确定发布吗？') : t('table', '确定下线吗？')}`"
                  @confirm="handleClick({ name: '发布', record, index })"
                >
                  <a>{{ record.status == 0 ? t('common', '发布') : t('common', '下线') }}</a>
                </a-popconfirm>
                <a @click="handleClick({ name: '编辑', record, index })"
                  >{{t('common', '编辑')}}</a
                >
              </div>
            </template>

            <template
              v-if="
                column.key === 'expiredTime' &&
                record.status > 0 &&
                record.submitTime &&
                dayjs(record.submitTime).isAfter(dayjs(record.expiredTime)) &&
                dayjs().isAfter(dayjs(record.expiredTime))
              "
            >
              <td :style="{ color: 'red' }">{{ text }}</td>
            </template>
          </template>
        </a-table>
      </div>
      <a-pagination
        style="text-align: center;margin-top:10px;"
        @change="show"
        v-model:current="pagination.current"
        show-size-changer
        v-model:pageSize="pagination.size"
        :total="pagination.totalElements"
      />
    </div>

    <a-modal v-model:open="modal.visible" :footer="null" :title="t('common', modal.name)">
      <a-form
        ref="formRef"
        v-bind="{ layout: 'vertical' }"
        :model="formModel"
        :rules="rules"
        :disabled="modal.formDisable"
      >
        <a-form-item has-feedback :label="t('modal', '任务标题')" name="title">
          <!-- <a-input v-model:value="formModel.title" autocomplete="off" placeholder="请输入任务标题"/> -->
          <a-textarea
            v-model:value="formModel.title"
            :placeholder="t('common', '请输入')"
            :auto-size="{ minRows: 2, maxRows: 7 }"
            :showCount="false"
          />
        </a-form-item>
        <a-form-item has-feedback :label="t('modal', '任务类型')" name="type">
          <a-select
            ref="select"
            v-model:value="formModel.type"
            style="width: 100%"
            :placeholder="t('common', '请选择')"
            @focus="focus"
            @change="handleChange"
          >
            <a-select-option :value="1">{{t('modal', '学习任务')}}</a-select-option>
            <a-select-option :value="0">{{t('modal', '项目任务')}}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item has-feedback :label="t('modal', '任务描述')" name="describe">
          <!-- <a-input v-model:value="formModel.describe" autocomplete="off" /> -->
          <a-textarea
            v-model:value="formModel.describe"
            :placeholder="t('common', '请输入')"
            :auto-size="{ minRows: 2, maxRows: 7 }"
            :showCount="false"
          />
        </a-form-item>
        <a-form-item
          v-if="modal.name == '编辑'"
          has-feedback
          :label="t('modal', '任务接收人')"
          name="studentId"
        >
          <a-select
            v-model:value="formModel.studentId"
            show-search
            :filter-option="filterStudentOption"
            :options="studentStructure"
            :placeholder="t('common', '请选择')"
            style="width: 100%"
            :field-names="{ label: 'studentName', value: 'studentId' }"
          ></a-select>
        </a-form-item>
        <!-- <a-form-item v-if="modal.name == '编辑'&&groupValue==''&&route.query.template==1" has-feedback label="任务接收人" name="studentId">
						<a-tree-select
    						v-model:value="formModel.studentId"
    						style="width: 100%"
							:treeDefaultExpandAll="true"
    						:tree-data="studentStructure.map(node => ({
    						  ...node,
    						  memberList: node.memberList.map(member => ({
    							...member,
    							name: member.studentId === node.leaderId ? `${member.name} (组长)` : member.name,
    						  }))
    						}))"
							placeholder="请选择任务接收人"
    						tree-checkable
    						allow-clear
    						:show-checked-strategy="SHOW_PARENT"
    						tree-node-filter-prop="label"
							:field-names="{
    						  children: 'memberList',
    						  label: 'name',
    						  value: 'studentId',
    						}"
							@change="()=>console.log(formModel.studentId)"
  						>
							
						
						</a-tree-select>
				</a-form-item> -->
        <a-form-item
          v-if="
            modal.name == '创建任务' &&
            groupValue == '' &&
            route.query.template == 1
          "
          has-feedback
          :label="t('modal', '任务接收人')"
          name="studentId"
        >
          <!-- <a-select v-model:value="formModel.studentId" mode="multiple" show-search
						:filter-option="filterStudentOption" :options="allStudentStructure" placeholder="请选择任务接收人"
						style="width:100%" :field-names="{ label: 'studentName', value: 'studentId' }"></a-select> -->
          <a-tree-select
            v-model:value="formModel.studentId"
            style="width: 100%"
            :treeDefaultExpandAll="true"
            :tree-data="
              studentStructure.map((node) => ({
                ...node,
                memberList: node.memberList.map((member) => ({
                  ...member,
                  name:
                    member.studentId === node.leaderId
                      ? `${member.name} (组长)`
                      : member.name,
                })),
              }))
            "
            :placeholder="t('common', '请选择')"
            tree-checkable
            allow-clear
            :show-checked-strategy="SHOW_PARENT"
            tree-node-filter-prop="label"
            :field-names="{
              children: 'memberList',
              label: 'name',
              value: 'studentId',
            }"
            @change="() => console.log(formModel.studentId)"
          >
          </a-tree-select>
        </a-form-item>

        <a-form-item
          v-if="
            (modal.name == '创建任务' && groupValue != '') ||
            (modal.name == '创建任务' && route.query.template == 0)
          "
          has-feedback
          :label="t('modal', '任务接收人')"
          name="studentId"
        >
          <a-select
            v-model:value="formModel.studentId"
            mode="multiple"
            show-search
            :filter-option="filterStudentOption"
            :options="studentStructure"
            :placeholder="t('common', '请选择')"
            style="width: 100%"
            :field-names="{ label: 'studentName', value: 'studentId' }"
          ></a-select>
        </a-form-item>
        <a-form-item has-feedback :label="t('modal', '任务分值')" name="scoreSetting">
          <a-input-number
            v-model:value="formModel.scoreSetting"
            style="width: 100%"
            :placeholder="t('common', '请输入')"
          />
        </a-form-item>
        <a-form-item has-feedback :label="t('modal', '任务截止时间')" name="expiredTime">
          <a-date-picker
            v-model:value="formModel.expiredTime"
            show-time
            style="width: 100%"
            :placeholder="t('common', '请选择')"
            @change="onChange"
            @ok="onOk"
          />
        </a-form-item>
        <a-form-item
          v-if="!modal.formDisable"
          style="text-align: center; padding-top: 20px"
        >
          <a-button type="primary" @click="handleSubmit" :loading="loading"
            >{{t('common', '提交')}}</a-button
          >
          <a-button style="margin-left: 20px" @click="modal.visible = false"
            >{{t('common', '取消')}}</a-button
          >
        </a-form-item>
      </a-form>
    </a-modal>
    <a-modal
      v-model:open="aiOpen"
      v-if="aiOpen"
      :maskClosable="false"
      :footer="null"
      title="AI生成任务"
      style="width: 1100px"
    >
      <div style="height: 460px">
        <minAi
          :rows="2"
          :hasHeader="false"
          refreshRecord
					:record="Math.random()"
          :initialData="modal.initialData"
          url="/ai/dify/system/subtask/chatMessages"
          @handleThought="handleThought"
        />
        <!-- <AIConsulting :initialData="modal.initialData" size="clear" type="subtask" agentImg=""
					@handleThought="handleThought" /> -->
        <!-- <AIConsulting size="clear" type="assignTasks" agentImg=""/> -->
      </div>
    </a-modal>

    <TaskDetail
      v-model:open="drawerVisible"
      :taskData="formModel"
      @update:visible="(data) => (drawerVisible = data)"
    />
  </div>
</template>
<script setup>
import { reactive, ref, onMounted, computed, h, createVNode } from 'vue'
import {
  getTeacherTaskList,
  addTasks,
  getTeacherTaskDetailById,
  deleteTeacherTask,
  modifyTaskStatus,
  getAllStudent,
  getGroupStudent,
  teacherModifyTasks,
  getWeekList,
} from '@/request/process/processTask.js'
import { getProjectMessage } from '@/request/projectSquare.js'
import { useRoute, useRouter } from 'vue-router'
import minRangePicker from '@/components/common/minRangePicker.vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import AIConsulting from '@/components/AIConsulting.vue'
import TaskDetail from './taskDetail.vue'
import { state, refreshMessages } from '@/stores/info.js'
import { Modal } from 'ant-design-vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import minAi from '@/components/common/minAi.vue'
import { t } from '@/i18n'
const selectedRowKeys = ref([])
const selectedRows = ref([])
const onSelectChange = (keys, rows) => {
  selectedRowKeys.value = keys
  selectedRows.value = rows
}

const groupValue = ref('')
function groupChange(value) {
  groupValue.value = value
  search(1)
}
let drawerVisible = ref(false)

const filterStudentOption = (input, option) => {
  return option.studentName.toLowerCase().indexOf(input.toLowerCase()) >= 0
}

// let expiredTime=ref()
const route = useRoute()
const router = useRouter()
let projectId = ref(route.query && route.query.id ? route.query.id : '')
let groupStudentStructure = ref([])
let allStudentStructure = ref([])
let studentStructure = ref([])

const teachingWeekOptions = ref([])

function filterWeekOption(input, option) {
  return option.name.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
onMounted(async () => {
  console.log('onMount')
  if (route.query.template == 1) {
    let res = await getAllStudent({
      projectId: projectId.value,
      teamMembers: true,
    })
    res.data = res.data.filter((item) => item.memberNumber > 0)
    res.data.forEach((item, i) => {
      res.data[i].name = item.teamName ? item.teamName : item.leaderName + '组'
      res.data[i].studentId = item.teamId
      // if(item.memberList&&item.memberList.length>0){
      // 	item.memberList.forEach((item)=>{
      // 		res.data[i].studentId.push(item.studentId)
      // 	})
      // }
    })
    allStudentStructure.value = res.data
    studentStructure.value = res.data
  }

  let weekData = await getWeekList()
  teachingWeekOptions.value = weekData.data
  groupValue.value = ''
})

const onChange = (value, dateString) => {
  formModel.expiredTime = dateString
}
const onOk = (value) => {
  formModel.expiredTime = value.format('YYYY-MM-DD HH:mm:ss')
  console.log('onOk: ', value.format('YYYY-MM-DD HH:mm:ss'))
}

let loading = ref(false)
const handleSubmit = async () => {
  console.log(modal)
  let v = await formRef.value.validate().catch((err) => false)
  if (!v) return message.error(t('common', '请检查表单数据'))
  let res = null
  loading.value = true
  if (modal.name == '创建任务') {
    let studentIds =
      formModel.value.studentId && formModel.value.studentId.length > 0
        ? [...formModel.value.studentId]
        : []
    let req = {
      ...formModel.value,
      expiredTime: formModel.value.expiredTime
        ? formModel.value.expiredTime.format('YYYY-MM-DD HH:mm:ss')
        : undefined,
      studentIds: studentIds,
    }
    loading.value = true
    res = await addTasks({
      data: req,
      projectId: projectId.value,
    })
  }
  if (modal.name == '编辑') {
    let req = {
      ...formModel.value,
      expiredTime: formModel.value.expiredTime
        ? formModel.value.expiredTime.format('YYYY-MM-DD HH:mm:ss')
        : undefined,
    }
    loading.value = true
    res = await teacherModifyTasks({
      data: req,
      projectId: projectId.value,
    })
  }
  // if (modal.name == '创建任务'){
  // console.log({data:req,projectId:projectId.value})
  //  res = await addTasks({data:req,projectId:projectId.value})
  //  console.log('创建任务',res)
  // }
  // else res = await projectModify(req)
  loading.value = false
  if (!res) return
  modal.visible = false
  message.success(t('common', '保存成功'))
  show()
}

function clear() {
  for (let key in searchData) {
    searchData[key] = undefined
  }
  search(1)
}

const searchData = reactive({
  search_AND_LIKE_title: '',
})
const pagination = ref({
  totalElements: 0,
  current: 1,
  size: 10,
})
const formModel = ref({})
const formRef = ref()
const modal = reactive({
  visible: false,
  formDisable: false,
  name: '',
})
const rules = {
  title: [
    {
      required: true,
      trigger: 'change',
    },
  ],
  type: [
    {
      required: true,
      trigger: 'change',
    },
  ],
  studentId: [
    {
      required: true,
      trigger: 'change',
    },
  ],
  expiredTime: [
    {
      required: true,
      trigger: 'change',
    },
  ],
}

const columns = [
  // {
  // 	title: '序号',
  // 	dataIndex: 'index',
  // 	customRender: ({
  // 		index
  // 	}) => index + 1,
  // 	width: 60,
  // 	fixed: 'left'
  // },
  {
    title: t('table', '来源'),
    dataIndex: 'source',
    width: 80,
    customRender: (record) => {
      if (record.text == 0) {
        return h(
          'span',
          {
            style: {
              padding: '4px 10px',
              backgroundColor: 'rgba(128, 94, 143, .7)',
              color: 'rgb(255,255,255)',
              borderRadius: '10px',
            },
          },
          'AI'
        )
      }
      return '人工'
    },
  },
  {
    title: t('table', '标题'),
    dataIndex: 'title',
    key: 'title',
    width: 120,
    ellipsis: true,
  },
  {
    title: t('table', '状态'),
    dataIndex: 'status',
    customRender: ({ text }) => {
      const statusMap = {
        0: t('control', '未发布'),
        1: t('control', '已发布'),
        2: t('control', '已完成'),
        3: t('control', '已评分'),
      }
      return statusMap[text] || ''
    },
  },
  {
    title: t('table', '负责人'),
    dataIndex: 'studentName',
  },
  {
    title: t('table', '任务类型'),
    dataIndex: 'type',
    customRender: ({ text }) => {
      const statusMap = {
        0: t('modal', '项目任务'),
        1: t('modal', '学习任务'),
      }
      return statusMap[text] || ''
    },
  },
  {
    title: t('table', '截止日期'),
    dataIndex: 'expiredTime',
    key: 'expiredTime',
  },
  // { title: t('table', '发布时间'), dataIndex: 'releaseTime', key: 'releaseTime' },
  // { title: t('table', '组别'), dataIndex: 'name', key: 'name' },
  {
    title: t('table', '教学周'),
    dataIndex: 'weekName',
    key: 'weekName',
  },
  {
    title: t('table', '操作'),
    dataIndex: 'operate',
    key: 'operate',
    width: 100,
  },
]
const tableData = ref([])
const show = async (page, pageSize) => {
  let req = {
    ...pagination.value,
    page: page ? page - 1 : pagination.value.current - 1,
    size: pageSize,
    ...searchData,
    search_AND_EQ_projectId: projectId.value,
    search_AND_EQ_teamId: groupValue.value,
  }
  let res = await getTeacherTaskList(req)
  if (!res) return
  // groupValue.value=''
  tableData.value = res.data ? res.data.content : []
  pagination.value = {
    ...pagination.value,
    ...res.data.page,
  }
}

function search(page, pageSize) {
  show(1, pageSize)
}

show()

let aiOpen = ref(false)
let scoringRequirements = ref('')
let conversationalStyle = ref('')

async function getStudentCreatedList() {
  if (groupValue.value == '' && route.query.template == 1) {
    studentStructure.value = allStudentStructure.value
  } else {
    let res = await getGroupStudent({
      projectId: projectId.value,
      search_AND_EQ_projectTeamId: groupValue.value,
    })
    studentStructure.value = res.data
  }
}
async function getStudentEditedList() {
  let res = await getGroupStudent({
    projectId: projectId.value,
    search_AND_EQ_projectTeamId: groupValue.value,
  })
  studentStructure.value = res.data
}
const delLoading = ref(false)
const handleClick = async ({ name, record, index }) => {
  let req = {},
    res = null
  console.log(name, record, index)
  switch (name) {
    case '创建任务':
      await getStudentCreatedList()
      formModel.value = {}
      modal.visible = true
      modal.formDisable = false
      modal.name = t('common','创建任务')
      formRef?.value?.resetFields()
      break
    case '查看':
      await getStudentCreatedList()
      res = await getTeacherTaskDetailById(record.id)
      console.log('查看', res)
      if (!res) return
      formModel.value = {
        ...res.data,
        expiredTime: res.data.expiredTime
          ? dayjs(res.data.expiredTime)
          : undefined,
      }
      drawerVisible.value = true

      break
    case '编辑':
      await getStudentEditedList()
      res = await getTeacherTaskDetailById(record.id)
      console.log('查看', res)
      if (!res) return
      formModel.value = {
        ...res.data,
        expiredTime: res.data.expiredTime
          ? dayjs(res.data.expiredTime)
          : undefined,
      }
      modal.visible = true
      modal.formDisable = false
      modal.name =t('编辑','编辑')
      formRef?.value?.resetFields()
      break
    case '删除':
      res = await deleteTeacherTask([record.id])
      console.log('查看', res)
      if (!res) return
      if (res && res.code == 200) {
        message.success(t('编辑','删除成功'))
        show()
      }
      // modal.formDisable=true
      // modal.visible = true
      // modal.name = '查看'
      break
    case '发布':
      let status = record.status
      res = await modifyTaskStatus({
        status: status == 0 ? 1 : 0,
        data: [record.id],
      })
      console.log('查看', res)
      if (!res) return
      if (res && res.code == 200) {
        message.success(status == 0 ? t('common', '发布成功') : t('common', '下线成功'))
        let pojectInfo = JSON.parse(
          sessionStorage.getItem('pojectInfo') || '{}'
        )
        refreshMessages(pojectInfo)
        show()
      }
      // modal.formDisable=true
      // modal.visible = true
      // modal.name = '查看'
      break
    case '批量发布':
      // let status = record.status
      res = await modifyTaskStatus({
        status: 1,
        data: [...selectedRowKeys.value],
      })
      console.log('查看', res)
      if (!res) return
      if (res && res.code == 200) {
        message.success(t('common', '操作成功'))
        selectedRowKeys.value = []
        search(1)
        let pojectInfo = JSON.parse(
          sessionStorage.getItem('pojectInfo') || '{}'
        )
        refreshMessages(pojectInfo)
        show()
      }
      // modal.formDisable=true
      // modal.visible = true
      // modal.name = '查看'
      break
    case '批量删除':
      // let status = record.status
      Modal.confirm({
        title: t('modal', '确认删除'),
        icon: createVNode(ExclamationCircleOutlined),
        content: t('modal', '你确认删除这些任务吗？'),
        okText: t('common', '确认'),
        cancelText: t('common', '取消'),
        onOk: async () => {
					delLoading.value = true
          res = await deleteTeacherTask([...selectedRowKeys.value])
					delLoading.value = false
          if (!res) return
          if (res && res.code == 200) {
            message.success(t('common', '操作成功'))
            selectedRowKeys.value = []
            search(1)
            let pojectInfo = JSON.parse(
              sessionStorage.getItem('pojectInfo') || '{}'
            )
            refreshMessages(pojectInfo)
            show()
          }
        },
        onCancel: () => {
          selectedRowKeys.value = []
        },
      })

      // modal.formDisable=true
      // modal.visible = true
      // modal.name = '查看'
      break
    case 'AI生成任务':
      aiOpen.value = true
      // taskld=record.id||''
      let pojectInfo = JSON.parse(sessionStorage.getItem('pojectInfo') || '{}')
      console.log('生成任务', pojectInfo)
      modal.initialData = {
        message: `userId:teacher_${state.userInfo.id}。projectId:${pojectInfo.id}。teamId:${groupValue.value} 。${t('ai', '进行任务分配，分配后让我确认')}`,
        placeholder: t('ai', `如果选择组分配方式，NanYangAZ 会默认将任务分配给组，并设置在当前时间所在的教学周为截至时间。如果需要将任务分配给个人，或补充其他信息（如分值设置、截止时间），请在对话中说明！`),
      }
      break
  }
}

async function handleThought(val) {
  if (val.tool.includes('saveTask')) {
    pagination.value.current = 1
    show()
  }
}
</script>

<style lang="scss" scoped>
.taskContainer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    border-radius: 10px;
    height: 80px;
    padding: 20px;
  }

  .content {
    height: calc(100% - 80px * 2 - 20px);
    margin-top: 20px;
    padding: 20px;
    overflow-y: auto;overflow-x: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 10px;

    :deep(.ant-table-wrapper) {
      height: 100%;
    }

    :deep(.ant-table) {
      height: 100%;
    }
  }
}
</style>
